package com.ethan.minimalist.ui.mine

import com.bumptech.glide.Glide
import com.cxz.kotlin.baselibs.base.BaseMvpActivity
import com.ethan.minimalist.R
import com.ethan.minimalist.bean.UserBean
import com.ethan.minimalist.constant.Constant
import com.ethan.minimalist.mvp.contract.IUpdateUserContract
import com.ethan.minimalist.mvp.presenter.UpdateUserPresenter
import com.google.gson.Gson
import com.gyf.immersionbar.ImmersionBar
import com.tencent.mmkv.MMKV
import kotlinx.android.synthetic.main.activity_personal_info.*

/**
 * @ClassName:      UpdateUserActivity
 * @Description:
 * @Author:         ethanWu
 * @CreateDate:     2020/3/18 10:06
 */
open class UpdateUserActivity : BaseMvpActivity<IUpdateUserContract.View,IUpdateUserContract.Presenter>() {

    private var mUser: UserBean?= null

    override fun createPresenter(): IUpdateUserContract.Presenter {
        return UpdateUserPresenter()
    }

    override fun attachLayoutRes(): Int {
        return R.layout.activity_personal_info
    }

    override fun initView() {
        super.initView()

        ImmersionBar.with(this@UpdateUserActivity)
            .statusBarView(top_view)
            .statusBarDarkFont(true, 0.2f)
            .init()
    }

    override fun initData() {
        super.initData()
        iv_back.setOnClickListener {
            onBackPressed()
        }

        tv_login_out.setOnClickListener {
            MMKV.defaultMMKV().clearAll()
            onBackPressed()
        }

        mUser = Gson().fromJson(MMKV.defaultMMKV().decodeString(Constant.USER),UserBean::class.java)
        if(mUser != null) {
            Glide.with(this).load(mUser?.avatar).into(iv_avatar)
            tv_nickName.text = mUser?.nickName
        }
    }

    override fun start() {
    }
}